<template>
  <div class="dashboard-container">
    <div class="bgc">
      <div
        class="title"
        style="
          width: 100%;
          color: #fff;
          font-weight: 500;
          font-size: 24px;

          box-sizing: border-box;
          padding-left: 20px;
          display: flex;
          align-items: center;
          margin-top: 20px;
          margin-bottom: 30px;
        "
      >
        添加/编辑设备
      </div>
      <el-steps :active="type" style="width: 500px; margin: 0 auto">
        <el-step title="基础配置" />
        <el-step title="高级配置" />
        <el-step title="预警配置" />
        <el-step title="完成" />
      </el-steps>
      <div v-if="type == 1" class="forms">
        <el-form ref="form" :model="form" :rules="rules" label-width="100px" class="demo-ruleForm">
          <el-form-item label="名称" prop="name">
            <el-input v-model="form.name" class="el-inputs" />
          </el-form-item>
          <el-form-item label="安装位置" prop="">
            <el-input v-model="form.location" class="el-inputs" />
          </el-form-item>
          <el-form-item label="组：" prop="">
            <el-input v-model="form.group" class="el-inputs" />
          </el-form-item>
          <el-form-item label="曲线类型：" prop="">
            <el-select v-model="form.line_type" placeholder="图表类型">
              <el-option label="平滑曲线" value="line" />
              <el-option label="柱状图" value="bar" />
            </el-select>
          </el-form-item>
          <el-form-item label="单位：" prop="">
            <el-input
              v-model="form.unit"
              class="el-inputs"
              style="background-color: transparent"
            />
          </el-form-item>
          <el-form-item label="备注" prop="">
            <el-input v-model="form.remark" type="textarea" />
          </el-form-item>
          <el-form-item class="" style="display: flex; justify-content: center">
            <el-button
              type="primary"
              style="margin: 0 auto"
              @click="submitForm('form')"
            >下一步</el-button>
          </el-form-item>
        </el-form>
      </div>
      <div v-if="type == 2" class="forms">
        <el-form ref="form" :model="form" :rules="rules" label-width="100px" class="demo-ruleForm">
          <el-form-item label="校准参数" prop="">
            <el-input v-model="form.calibration_factors" class="el-inputs" />
          </el-form-item>
          <el-form-item label="公式" prop="">
            <el-input v-model="form.formula" class="el-inputs" />
          </el-form-item>
          <el-form-item label="基准值" prop="">
            <el-input v-model="form.base_value" class="el-inputs" />
          </el-form-item>
          <el-form-item label="基准值时间：" prop="">
            <el-date-picker
              v-model="form.base_time"
              type="date"
              placeholder="选择日期"
              style="background-color: transparent"
            />
          </el-form-item>
          <el-form-item label="小数位数：" prop="">
            <el-input
              v-model="form.decimals"
              class="el-inputs"
              style="background-color: transparent"
            />
          </el-form-item>
          <el-form-item label="Ascli文件" prop="">
            <el-input
              v-model="form.ascii_file"
              class="el-inputs"
              style="background-color: transparent"
            />
          </el-form-item>
          <el-form-item label="在文件第几列" prop="">
            <el-input
              v-model="form.in_file"
              class="el-inputs"
              style="background-color: transparent"
            />
          </el-form-item>
          <el-form-item label="日期格式化" prop="">
            <el-select v-model="form.date_format" placeholder="日期格式化">
              <el-option label="Y-M-D H:I" value="2006-01-02 15:04" />
              <el-option label="D/M I:H" value="01/02 04:05" />
            </el-select>
          </el-form-item>
          <el-form-item class="" style="display: flex; justify-content: center">
            <el-button
              type="primary"
              style="margin: 0 auto; background-color: transparent; margin-right: 20px"
              @click="out()"
            >上一步</el-button>
            <el-button
              type="primary"
              style="margin: 0 auto"
              @click="submitForm('form')"
            >下一步</el-button>
          </el-form-item>
        </el-form>
      </div>

      <div v-if="type == 3" class="forms">
        <el-form ref="form" :model="form" :rules="rules" label-width="100px" class="demo-ruleForm">
          <el-form-item label="看门狗阈值" prop="">
            <el-input v-model="form.watch_dog" class="el-inputs" />
          </el-form-item>
          <el-form-item label="橙色预警下限" prop="">
            <el-input v-model="form.orange_lower" class="el-inputs" />
          </el-form-item>
          <el-form-item label="橙色预警上限" prop="">
            <el-input v-model="form.orange_upper" class="el-inputs" />
          </el-form-item>
          <el-form-item label="红色预警下限" prop="">
            <el-input v-model="form.red_lower" class="el-inputs" />
          </el-form-item>
          <el-form-item label="红色预警上限" prop="">
            <el-input v-model="form.red_upper" class="el-inputs" />
          </el-form-item>
          <el-form-item label="黑色预警下限" prop="">
            <el-input v-model="form.black_lower" class="el-inputs" />
          </el-form-item>
          <el-form-item label="黑色预警上限" prop="">
            <el-input v-model="form.black_upper" class="el-inputs" />
          </el-form-item>

          <el-form-item class="" style="display: flex; justify-content: center">
            <el-button
              type="primary"
              style="margin: 0 auto; background-color: transparent; margin-right: 20px"
              @click="out()"
            >上一步</el-button>
            <el-button
              type="primary"
              style="margin: 0 auto"
              @click="submitForms('form')"
            >提交</el-button>
          </el-form-item>
        </el-form>
      </div>
    </div>
  </div>
</template>
<script>
import { sensor_edit } from '@/api/sensor'
export default {
  data() {
    return {
      info: {},
      type: 1,
      form: {
        id: 0,
        project_id: this.$store.getters.currentProjectId,
        name: '',
        location: '',
        group: '',
        line_type: '',
        unit: '',
        remark: '',
        calibration_factors: '',
        formula: '',
        base_value: '',
        base_time: '',
        decimals: 0,
        ascii_file: '',
        in_file: 0,
        date_format: 'Y-m-d H:i:s',
        watch_dog: 0,
        orange_lower: 0,
        orange_upper: 0,
        red_lower: 0,
        red_upper: 0,
        black_lower: 0,
        black_upper: 0
      },
      rules: {
        name: [{ required: true, message: '请输入正确的名称', trigger: 'blur' }]
        // decimals: [{ type: 'number', message: '请输入正确的小数位数', trigger: 'blur' }]
        // date1: [{ type: 'date', required: true, message: '请选择日期', trigger: 'change' }],
        // date2: [{ type: 'date', required: true, message: '请选择时间', trigger: 'change' }],
        // type: [
        //   { type: 'array', required: true, message: '请至少选择一个活动性质', trigger: 'change' }
        // ],
        // resource: [{ required: true, message: '请选择活动资源', trigger: 'change' }],
        // desc: [{ required: true, message: '请填写活动形式', trigger: 'blur' }]
      }
    }
  },
  computed: {},
  created() {
    // this.optionsValue = this.options[0]
    if (JSON.parse(this.$route.query.item)) {
      const tom = JSON.parse(this.$route.query.item)
      this.form = tom
    }
  },
  methods: {
    submitForm(formName) {
      this.$refs[formName].validate(valid => {
        if (valid) {
          this.type = this.type + 1
        } else {
          console.log('error submit!!')
          return false
        }
      })
    },
    submitForms(formName) {
      this.$refs[formName].validate(valid => {
        sensor_edit(this.form).then(res => {
          if (res.code === 200) {
            this.$message({
              message: '修改成功',
              type: 'success'
            })
            this.type = this.type + 1

            setTimeout(() => {
              this.$router.push({
                path: 'equipmentManagement',
                query: { project_id: this.$store.getters.currentProjectId }
              })
            }, 2000)
          }
        })
      })
    },
    out() {
      this.type = this.type - 1
    },
    resetForm(formName) {
      this.$refs[formName].resetFields()
    }
  }
}
</script>

<style lang="scss" scoped>
.bgc {
  width: 90%;
  margin: 0 auto;
  height: 80vh;
  border: 1px solid rgb(101, 166, 231);
  // background-color: red;
  //   width: 400px;
  //  height: 300px;
  //  background-color: #222 !important;
  //  border-radius: 10px;
  //  display: flex;
  //  align-items: center;
  //  justify-content: center;
  //  font-size: 20px;
  //  color: #fff;
  //  font-weight: 800;
  //  position: relative;
  //  z-index: 20;
  // background: url('../../views/images/编组-3-20240612172302722_副本.png');
  background-size: 100% 100%;
  background-repeat: no-repeat;
  // background-color: red;
}
::v-deep .el-step__title.is-success {
  color: #fff;
}
::v-deep .el-step__title.is-process {
  color: #ccc !important;
}
.demo-ruleForm {
  width: 500px;
  margin: 0 auto;
  margin-top: 20px;
}
.forms {
  width: 800px;
  margin: 0 auto;
}
::v-deep .el-input__inner {
  background-color: transparent !important;
  color: #fff;
}
::v-deep .el-textarea__inner {
  background-color: transparent !important;
  color: #fff;
}
</style>
